package com.travel.server.manager.impl.command.adversiting;

import com.travel.common.CommonConstant;
import com.travel.server.manager.dto.request.advertising.QueryContentMessageRequest;
import com.travel.server.manager.dto.response.advertising.QueryContentMessageResponse;
import com.travel.server.manager.impl.command.AbstractCommand;
import com.travel.server.manager.impl.dal.ContentDal;
import com.travel.server.manager.model.ContentInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: LiZhenhui
 * @Date: 2018/12/20 15:48
 * @Desc:
 */
@Component
public class QueryContentMessageCommand extends AbstractCommand<QueryContentMessageRequest, QueryContentMessageResponse> {

    @Autowired
    private ContentDal contentDal;

    @Override
    protected void checkInput(QueryContentMessageRequest request) {
        if(request.getType() == null){
            throwInvalidParam();
        }
    }

    @Override
    public QueryContentMessageResponse handle(QueryContentMessageRequest request) {
        QueryContentMessageResponse response = new QueryContentMessageResponse();
        ContentInfo contentInfo = contentDal.select();
        if(contentInfo == null){
            return response;
        }
        Integer type = request.getType();
        if(CommonConstant.ABOUT_US.equals(type)){
            response.setMessage(contentInfo.getAboutUs());
        }else if(CommonConstant.CONTACT_US.equals(type)){
            response.setMessage(contentInfo.getContactUs());
        }else if(CommonConstant.JOIN_US.equals(type)){
            response.setMessage(contentInfo.getJoinUs());
        }else{
            throwInvalidParam();
        }
        return response;
    }
}
